import Vue from 'vue'
import VueRouter from 'vue-router'
// import typing from '../components/typing.vue'
// import list from '../components/list.vue'
import detail from '../components/detail.vue'
import entrance from '../components/entrance'
import home from '../components/home.vue'
import store from '../store/store'
// console.log(store.state.tx)
Vue.use(VueRouter)

const routes = [
  {path:'/entrance',name:'entrance',component:entrance},
  {path:'/home',component:{render:(e)=>e("router-view")},
      children:[
          {path:'',name:home,component:home},
          {path:'typing',component:{render:(e)=>e('router-view')},
            children:[
                {path:'look_typing',name:'look_typing',component:()=>import('../components/typing.vue'),props:{type:'look'}},
                {path:'hear_typing',name:'hear_typing',component:()=>import('../components/typing.vue'),props:{type:'hear'}},
                {path:'blind_typing',name:'blind_typing',component:()=>import('../components/typing.vue'),props:{type:'blind'}},
                {path:'list',name:'list',component:()=>import('../components/list.vue')},
                {path:'list_contest',name:'list_contest',component:()=>import('../components/list_contest.vue')},

            ]
          },
          {path:'designC',component:{render:(e)=>e('router-view')},
            children:[
                {path:'apply',name:'apply',component:()=>import('../assets/views/designComponent/apply/apply.vue')},
                {path:'apply_list',name:'apply_list',component:()=>import('../assets/views/designComponent/apply_list.vue')},
                {path:'publish_article',name:'publish_article',component:()=>import('@/assets/views/home/article/publish_article.vue')}
            ]
          },
          {path:'tool',component:{render:(e)=>e('router-view')},
          children:[
              {path:'music',name:'music',component:()=>import('../assets/views/home/tool/music.vue')}
          ]},
          {path:'article',name:'article',component:()=>import('../assets/views/home/article/article.vue')}
      ]
      },
  {path:'/detail',name:'detail',component:detail}

]
const router = new VueRouter({
  base: process.env.BASE_URL,
  routes,
  mode:'hash'
})
router.beforeEach((to,from,next)=>{
    window.speechSynthesis.cancel(store.state.Utter)
    // console.log(to.path)
    if(to.path=='/'){
        // console.log(123)
    next('/home')
  }else if(to.path=='/entrance'){
        // alert(123)
    next()
  }else{
        // alert(22)
    let token = localStorage.getItem('Authorization');
        // to.path=='/home/article'
        // console.log(token)
    if (to.path=='/home'||to.path=='/home/article'||(token!==null&&token!=='')){
        // alert(333)
        next();
    } else{
        // alert('使用此功能前需先登录')
        // prompt()
        // comfir
        let a = confirm("使用此功能前需先登录")
        if (a){

            next('/entrance')
        }
        // this.$message.info({
        //     message:'请先登录'
        // })
    }
  }
})

export default router